package org.leumasjaffe.math.probability;

import java.util.Random;

import org.eclipse.jdt.annotation.NonNull;

public class ExponentialRV extends AbstractRV{
	final double lambda;
	
	public ExponentialRV(double lambda) {
		this.lambda = lambda;
	}
	
	public ExponentialRV(@NonNull Random r, double lambda) {
		super(r);
		this.lambda = lambda;
	}

	@Override
	public double getEV() {
		return 1/this.lambda;
	}

	@Override
	public double getVar() {
		return 1/(this.lambda*this.lambda);
	}

	@Override
	public double getP(double x) {
		return this.lambda*Math.exp(-this.lambda*x);
	}

	@Override
	public double calcX(double p) {
		if (!isProb(p)) throw new IllegalArgumentException("Arguement is not a valid probability");
		return -Math.log(1-p)/this.lambda;
	}

	@Override
	public double getF(double x) {
		return 1 - Math.exp(-this.lambda*x);
	}
	
}
